package net.designbased.jspfire.util;

import net.designbased.jspfire.ChartType;

/**
 *
 * @author chenhongliang
 */
public class Utility {
    public static ChartType ConverToChartType(String chartType)
    {
        ChartType cType;
        cType = (ChartType)Enum.valueOf(ChartType.class, chartType);

        return cType;
    }

    public static Boolean IsCompatible(ChartType currentRenderAs, ChartType otherRenderAs)
    {
        String[] compatibleTypes = { "Column", "Line", "Area", "StackedColumn", "StackedArea", "Point", "Bubble" };
        String[] uncompatibleTypes = { "Bar", "StackedBar", "Pie", "Doughnut, StreamLineFunnel, SectionFunnel" };
        String currcompatible = "compatible";
        String othercompatible = "compatible";

        int compatible;

        for (int i = 0; i < compatibleTypes.length; i++)
        {
            if (otherRenderAs == Utility.ConverToChartType(compatibleTypes[i]))
            {
                othercompatible = "compatible";
                break;
            }
            else if (otherRenderAs == ChartType.Pie || otherRenderAs == ChartType.Doughnut)
            {
                othercompatible = "pieType";
                break;
            }
            else if (otherRenderAs == ChartType.SectionFunnel || otherRenderAs == ChartType.StreamLineFunnel)
            {
                othercompatible = "sectionFunnelType";
                break;
            }
            else if (otherRenderAs == ChartType.Bar || otherRenderAs == ChartType.StackedBar || otherRenderAs == ChartType.StackedBar100)
            {
                othercompatible = "barType";
                break;
            }
        }

        for (int i = 0; i < compatibleTypes.length; i++)
        {
            if (currentRenderAs == Utility.ConverToChartType(compatibleTypes[i]))
            {
                currcompatible = "compatible";
                break;
            }
            else if (currentRenderAs == ChartType.Pie || currentRenderAs == ChartType.Doughnut)
            {
                currcompatible = "pieType";
                break;
            }
            else if (otherRenderAs == ChartType.SectionFunnel || otherRenderAs == ChartType.StreamLineFunnel)
            {
                currcompatible = "sectionFunnelType";
                break;
            }
            else if (currentRenderAs == ChartType.Bar || currentRenderAs == ChartType.StackedBar || currentRenderAs == ChartType.StackedBar100)
            {
                currcompatible = "barType";
                break;
            }
        }

        if ("compatible".equalsIgnoreCase(othercompatible) && !"compatible".equalsIgnoreCase(currcompatible))
        {
            compatible = 0;
        }
        else if ("pieType".equalsIgnoreCase(othercompatible))
        {
            compatible = 0;
        }
        else if ("sectionFunnelType".equalsIgnoreCase(othercompatible))
        {
            compatible = 0;
        }
        else if ("barType".equalsIgnoreCase(othercompatible))
        {
            if ("barType".equalsIgnoreCase(currcompatible))
            {
                compatible = 0;
            }
            else
            {
                compatible = 1;
            }
        }
        else
        {
            compatible = 1;
        }

        return compatible == 0 ? false : true;
    }
}
